<?php
// Module Definition
$module['name'] = 'BW Quota';
$module['description'] = 'Checks and warns about quotas on bandwidth usage.';
$module['depends'] = Array('apache', 'mod_cband');

switch($action) {
	case 'enable':
		global $cfg;
		$SQL = 'INSERT INTO crons(month, week, day, hour, minute, user, comment, fork, timeout, hook, createdby)
			VALUES("*", "*", "*", "*", "1", "webcp", "Run BW quota checks.", 1, 0, "server:bwquota:check", "bwquota.mod.phps")';
		$res = mysql_query($SQL);
		$SQL = 'INSERT INTO crons(month, week, day, hour, minute, user, comment, fork, timeout, hook, createdby)
			VALUES("*", "*", "*", "3", "30", "webcp", "Send BW quota warnings.", 1, 0, "server:bwquota:warn", "bwquota.mod.phps")';
		$res = mysql_query($SQL);
		$SQL = 'INSERT INTO crons(month, week, day, hour, minute, user, comment, fork, timeout, hook, createdby)
			VALUES("*", "1", "1", "0", "1", "webcp", "Reset BW usage.", 1, 0, "server:bwquota:reset", "bwquota.mod.phps")';
		$res = mysql_query($SQL);
		if (!$res)
			return $res;
		break;
	case 'disable':
		global $cfg;
		$SQL = 'DELETE FROM crons WHERE createdby = "bwquota.mod.phps"';
		$res = mysql_query($SQL);
		if (!$res)
			return $res;
		break;
	case 'hook':
		register_hook('server:bwquota:warn', 'bw_quota_warn');
		register_hook('server:bwquota:reset', 'bw_quota_reset');
		break;
}
?>